package cn.janus.exception;


import cn.janus.response.Result;
import org.springframework.validation.BindException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class JanusExceptionHandler {
    @ExceptionHandler(BindException.class)
    public Result BindExceptionHandler(BindException bindException) {
        return Result.fail(bindException.getAllErrors().get(0).getDefaultMessage());
    }

    @ExceptionHandler(ServiceException.class)
    public Result ServiceExceptionHandler(ServiceException serviceException) {
        return Result.fail(serviceException.getMessage());
    }

    @ExceptionHandler(IllegalArgumentException.class)
    public Result IllegalArgumentExceptionHandler(IllegalArgumentException illegalArgumentException) {
        return Result.fail(illegalArgumentException.getMessage());
    }
}
